<?php
// +----------------------------------------------------------------------
// | ThinkAdmin
// +----------------------------------------------------------------------
// | 版权所有 2018~2018 GoMaoMao [ http://www.gomaomao.com ]
// +----------------------------------------------------------------------
// | 官方网站: http://think.gomaomao.com
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | 联系方式：GoMaoMao <vip.vvm@qq.com>
// +----------------------------------------------------------------------
// | github开源项目：https://gitee.com/gomaomao.com/ThinkAdmin
// +----------------------------------------------------------------------

namespace app\miniprogram\controller;

use controller\BasicAdmin;
use service\DataService;
use think\Db;

/**
 * 单页管理
 * Class Goods
 * @package app\store\controller
 * @author Anyon <zoujingli@qq.com>
 * @date 2017/03/27 14:43
 */
class Onepage extends BasicAdmin
{

	/**
	 * 定义当前操作表名
	 * @var string
	 */
	public $table = 'mp_onepage';

	/**
	 * 普通内容
	 * @return array|string
	 * @throws \think\Exception
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	public function index()
	{
		$this->title = '单页管理';
		$get         = $this->request->get();
		$db          = Db::name($this->table);
		$db->where('website', session('website'));
		return parent::_list($db->order('id Asc'));
	}


	/**
	 * 添加
	 * @return array|string
	 * @throws \think\Exception
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	public function add()
	{
		return $this->_form($this->table, 'form');
	}

	/**
	 * 编辑
	 * @return array|string
	 * @throws \think\Exception
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	public function edit()
	{
		return $this->_form($this->table, 'form');
	}
	/**
	 * 表单数据处理
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \think\exception\DbException
	 */
	protected function _form_filter(&$vo)
	{
		if ($this->request->isPost()) {
			$vo['website']   = session('website');
			$vo['uid']       = session('user.id');
			$vo['update_at'] = time();
		}
	}


	/**
	 * 删除内容
	 * @throws \think\Exception
	 * @throws \think\exception\PDOException
	 */
	public function del()
	{
		if (DataService::update($this->table)) {
			$this->success("内容删除成功！", '');
		}
		$this->error("内容删除失败，请稍候再试！");
	}


}
